<template>
  <div style="width: 100%">
    <template>
      <div v-if="mode === 'edit'">
        <div v-if="cardList && cardList.length > 0">
          <div v-for="item in cardList" :key="item" >
            <div style="box-shadow:  0px 0px 1px 0.5px #ccc;margin-bottom:5px;border-radius: 4px;">
              <img
                :src="item.url"
                :style="{
                  width: cardWidth + 'px',
                  height: cardHeight + 'px',
                }"
              />
              <div style="padding: 14px">
                <span>{{ item.title }}</span>
                <div class="bottom clearfix">
                  <time class="time">{{ item.desc }}</time>
                  <!-- <el-button type="text" class="button">操作按钮</el-button> -->
                </div>
              </div>
            </div>
              <!-- <van-card :desc="item[0].desc" :title="item[0].title" :thumb="ietm[0].url" /> -->
          </div>
        </div>
        <div v-else>
          <van-card :desc="carddesc" :title="cardtitle" :thumb="cardUrl" />
        </div>
      </div>
      <div v-else>
        {{ value }}
      </div>
    </template>
  </div>
</template>
<script>
import datasource from "../../mixins/steps-datasource";
export default {
  name: "pm-card",
  mixins: [datasource],
  props: {
    value: {
      type: String | Number | Object | Array,
    },
    mode: {
      // 编辑态: edit, 查看态:view , 用于在子表格内切换状态
      default: "edit",
    },
    readonly: {
      default: false,
    },
    disabled: {
      default: false,
    },
    cardtitle: {
      default: "好吃的汉堡",
    },
    cardUrl: {
      default: "https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg",
    },
    carddesc: {
      default: "描述说明",
    },
    cardWidth: {
      default: "",
    },
    cardHeight: {
      default: "",
    },
  },

  mounted() {
    console.log(this.settings, this.icon, this.viewCode, this.viewId);
  },
  methods: {},
  data() {
    return {
      cardList: [],
    };
  },
  watch: {
    options: {
      immediate: true,
      deep: true,
      handler(val) {
        if (val && val.length) {
          this.cardList = val.map((item) => {
            return {
              url: item._data.url,
              title: item._data.title,
              desc: item._data.desc,
            };
          });
        }
      },
    },
  },
};
</script>
<style lang="scss" scoped>
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
</style>
